/*
 * Lab6D.cpp
 *
 *  Created on: Mar 10, 2014
 *      Author: Anthony Varghese
 *
 */

#include <iostream>
using namespace std;

class LinkedList{
private:
	struct Node{
		int data;
		Node* next;
		~Node(){
			delete next; // can check if it is nullptr but don't have to
		}
	};
public:
	LinkedList(){
		first = nullptr;
	}

	~LinkedList(){
		delete first;
	}

	void print() const {
		print( first );
	}

	void insert(const int d){
		Node* temp = new Node;
		temp->data = d;
		temp->next = first;
		first = temp;
	}
private:
	Node* first;
	void print(Node* p) const {
		if (p == nullptr){
			cout << endl;
			return;
		}
		cout << p->data << " ";
		print(p->next);
	}
};


void printsearchresult(const int key, const bool result){
    cout << "  The number " << key << " was";
    cout << ( (result) ? " " : " not ");
    cout << "found in the list." << endl;
}

int main() {
    cout << "CSIS 237 Lab 6 Part D" << endl; // prints a greeting
    int a[] = { 1, 2, 3, 4, 5, 6};

    LinkedList list;
    for(int i=0; i<6; i++)
        list.insert( a[i] );

    list.print();

    /* Step 3
    cout << "Searching the list ... " << endl;
    int number = 3;
    bool found = list.search( number );
    printsearchresult( number, found );
    number =  1;  found = list.search( number ); printsearchresult( number, found );
    number = 10;  found = list.search( number ); printsearchresult( number, found );
    number =  4;  found = list.search( number ); printsearchresult( number, found );
     */
    return 0;
}
